home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / ButtonModel.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  5.8 KB  |  216 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)ButtonModel.java    1.20 98/08/26
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package javax.swing;
  15.  
  16.  
  17. import java.awt.event.*;
  18. import java.awt.*;
  19. import javax.swing.event.*;
  20.  
  21. /**
  22.  * State Model for buttons.
  23.  * This model is used for checkboxes and radiobuttons, which are
  24.  * special kinds of buttons, as well as for normal buttons.
  25.  * For checkboxes and radiobuttons, pressing the mouse selects
  26.  * the button. For normal buttons, pressing the mouse "arms" the
  27.  * button. Releasing the mouse over the button then initiates a
  28.  * <i>button</i> press, firing its action event. Releasing the 
  29.  * mouse elsewhere disarms the button.
  30.  * <p>
  31.  * In use, a UI will invoke {@link #setSelected()} when a mouse
  32.  * click occurs over a checkbox or radiobutton. It will invoke
  33.  * {@link #setArmed} when the mouse is pressed over a regular
  34.  * button and invoke {@link #setPressed} when the mouse is released.
  35.  * If the mouse travels outside the button in the meantime, 
  36.  * <code>setArmed(false)</code> will tell the button not to fire
  37.  * when it sees <code>setPressed</code>. (If the mouse travels 
  38.  * back in, the button will be rearmed.)
  39.  * <blockquote>
  40.  * <b>Note: </b><br>
  41.  * A button is triggered when it is both "armed" and "pressed".
  42.  * </blockquote>
  43.  *
  44.  * @version 1.20 08/26/98
  45.  * @author Jeff Dinkins
  46.  */
  47. public interface ButtonModel extends ItemSelectable {
  48.     
  49.     /**
  50.      * Indicates partial commitment towards pressing the
  51.      * button. 
  52.      *
  53.      * @return true if the button is armed, and ready to be pressed
  54.      * @see #setArmed
  55.      */
  56.     boolean isArmed();     
  57.         
  58.     /**
  59.      * Indicates if the button has been selected. Only needed for
  60.      * certain types of buttons - such as RadioButton or Checkbox.
  61.      *
  62.      * @return true if the button is selected
  63.      */
  64.     boolean isSelected();
  65.         
  66.     /**
  67.      * Indicates if the button can be selected or pressed by
  68.      * an input device (such as a mouse pointer). (Checkbox-buttons
  69.      * are selected, regular buttons are "pressed".)
  70.      *
  71.      * @return true if the button is enabled, and therefore
  72.      *         selectable (or pressable)
  73.      */
  74.     boolean isEnabled();
  75.         
  76.     /**
  77.      * Indicates if button has been pressed.
  78.      *
  79.      * @return true if the button has been pressed
  80.      */
  81.     boolean isPressed();
  82.  
  83.     /**
  84.      * Indicates that the mouse is over the button.
  85.      *
  86.      * @return true if the mouse is over the button
  87.      */
  88.     boolean isRollover();
  89.  
  90.     /**
  91.      * Marks the button as "armed". If the mouse button is
  92.      * released while it is over this item, the button's action event
  93.      * fires. If the mouse button is released elsewhere, the
  94.      * event does not fire and the button is disarmed.
  95.      * 
  96.      * @param b true to arm the button so it can be selected
  97.      */
  98.     public void setArmed(boolean b);
  99.  
  100.     /**
  101.      * Selects or deselects the button.
  102.      *
  103.      * @param b true selects the button,
  104.      *          false deselects the button.
  105.      */
  106.     public void setSelected(boolean b);
  107.  
  108.     /**
  109.      * Enables or disables the button.
  110.      * 
  111.      * @param b true to enable the button
  112.      * @see #isEnabled
  113.      */
  114.     public void setEnabled(boolean b);
  115.  
  116.     /**
  117.      * Sets the button to pressed or unpressed.
  118.      * 
  119.      * @param b true to set the button to "pressed"
  120.      * @see #isPressed
  121.      */
  122.     public void setPressed(boolean b);
  123.  
  124.     /**
  125.      * Sets or clears the button's rollover state
  126.      * 
  127.      * @param b true to turn on rollover
  128.      * @see #isRollover
  129.      */
  130.     public void setRollover(boolean b);
  131.  
  132.     /**
  133.      * Sets the keyboard mnemonic (shortcut key or
  134.      * accelerator key) for this button.
  135.      *
  136.      * @param key an int specifying the accelerator key
  137.      */
  138.     public void setMnemonic(int key);
  139.  
  140.     /**
  141.      * Gets the keyboard mnemonic for this model
  142.      *
  143.      * @return an int specifying the accelerator key
  144.      * @see #setMnemonic
  145.      */
  146.     public int  getMnemonic();
  147.  
  148.     /**
  149.      * Sets the actionCommand string that gets sent as part of the
  150.      * event when the button is pressed.
  151.      *
  152.      * @param s the String that identifies the generated event
  153.      */
  154.     public void setActionCommand(String s);
  155.  
  156.     /**
  157.      * Returns the action command for this button.
  158.      *
  159.      * @return the String that identifies the generated event
  160.      * @see #setActionCommand
  161.      */
  162.     public String getActionCommand();
  163.  
  164.     /**
  165.      * Identifies the group this button belongs to --
  166.      * needed for radio buttons, which are mutually
  167.      * exclusive within their group.
  168.      *
  169.      * @param group the ButtonGroup this button belongs to
  170.      */
  171.     public void setGroup(ButtonGroup group);
  172.     
  173.     /**
  174.      * Adds an ActionListener to the button.
  175.      *
  176.      * @param l the listener to add
  177.      */
  178.     void addActionListener(ActionListener l);
  179.  
  180.     /**
  181.      * Removes an ActionListener from the button.
  182.      *
  183.      * @param l the listener to remove
  184.      */
  185.     void removeActionListener(ActionListener l);
  186.  
  187.     /**
  188.      * Adds an ItemListener to the button.
  189.      *
  190.      * @param l the listener to add
  191.      */
  192.     void addItemListener(ItemListener l);
  193.  
  194.     /**
  195.      * Removes an ItemListener from the button.
  196.      *
  197.      * @param l the listener to remove
  198.      */
  199.     void removeItemListener(ItemListener l);
  200.  
  201.     /**
  202.      * Adds a ChangeListener to the button.
  203.      *
  204.      * @param l the listener to add
  205.      */
  206.     void addChangeListener(ChangeListener l);
  207.  
  208.     /**
  209.      * Removes a ChangeListener from the button.
  210.      *
  211.      * @param l the listener to remove
  212.      */
  213.     void removeChangeListener(ChangeListener l);
  214.  
  215. }
  216.